home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / lib / scantest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  811 b   |  48 lines

  1.  
  2. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  3.  
  4. #include "../ir/cdialect.h"
  5. #include <stdio.h>
  6. /* #include <sys/types.h>*/
  7. #include <sys/stat.h>
  8. #include "pdftw.h"
  9.  
  10. extern int alphasort();
  11.  
  12. static int
  13. filesonly(e)
  14.     struct dirent *e;
  15. {
  16.     struct stat sb;
  17.  
  18.     return(stat(e->d_name, &sb) >= 0 && (sb.st_mode & S_IFMT) == S_IFREG);
  19. }
  20.  
  21. main(ac, av)
  22.     int ac;
  23.     char *av[];
  24. {
  25.     register int i;
  26.     register int j;
  27.     struct dirent **list;
  28.  
  29.     if (ac != 2) {
  30.         fprintf(stderr, "usage: %s dirname\n", av[0]);
  31.         exit(1);
  32.     }
  33.     if (chdir(av[1]) < 0) {
  34.         perror(av[1]);
  35.         exit(1);
  36.     }
  37.     if ((i = scandir(".", &list, filesonly, alphasort)) < 0) {
  38.         perror("Error reading directory");
  39.         exit(1);
  40.     }
  41.     for (j = 0; j < i; j++)
  42.         printf("%s\n", list[j]->d_name);
  43.     for (j = 0; j < i; j++)
  44.         free((char *)list[j]);
  45.     free((char *)list);
  46.     exit(0);
  47. }
  48.